Skip to content

Add date subheaders to the RS comment list - #23139

Merged
nbradbury merged 6 commits into
trunkfrom
issue/rs-comments-subheaders
Jul 24, 2026
Merged

Add date subheaders to the RS comment list#23139
nbradbury merged 6 commits into
trunkfrom
issue/rs-comments-subheaders

Conversation

@nbradbury

@nbradbury nbradbury commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What

Adds date-group subheaders to the RS comment list matching the legacy comments list.

Testing

  1. Enable the RS unified comments experimental feature and select an application-password site.
  2. Open Comments and confirm rows are grouped under all-caps date headers ("Today", "Yesterday", a date, or a relative span), with a new header wherever the date label changes.
headers

Interleave date-group headers into the rs comment list, matching the legacy
list. A new withDateHeaders() groups consecutive comments by their existing
relativeDate label (the same javaDateToTimeSpan value legacy groups by) and
inserts a header row on each change; the LazyColumn renders headers and
comments as distinct row types.
@dangermattic

dangermattic commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr23139-ef34802
Build Number1498
Application IDcom.jetpack.android.prealpha
Commitef34802
Installation URL7fmg8peuv9ss8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr23139-ef34802
Build Number1498
Application IDorg.wordpress.android.prealpha
Commitef34802
Installation URL108f3gnpt86co
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.54054% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.83%. Comparing base (e05eaf0) to head (ef34802).

Files with missing lines Patch % Lines
...ndroid/ui/commentsrs/screens/CommentsRsListItem.kt 0.00% 13 Missing ⚠️
...d/ui/commentsrs/screens/CommentsRsTabListScreen.kt 0.00% 8 Missing ⚠️
...rdpress/android/ui/commentsrs/CommentsRsListRow.kt 93.75% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #23139   +/-   ##
=======================================
  Coverage   37.83%   37.83%           
=======================================
  Files        2344     2345    +1     
  Lines      127482   127515   +33     
  Branches    17703    17711    +8     
=======================================
+ Hits        48229    48244   +15     
- Misses      75296    75313   +17     
- Partials     3957     3958    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Key each date header by its label instead of the group's first comment id, so
  a header stays stable (no remove+add re-animation) when a newer comment is
  prepended into an existing date group. Labels are unique per contiguous group
  given the date sort. Drops the now-unneeded keyId field.
- Uppercase the header label with the default locale, matching the legacy
  subheader's locale-aware textAllCaps (Kotlin's no-arg uppercase() is
  Locale.ROOT and mis-cases e.g. Turkish month names).
@wpmobilebot

This comment was marked as resolved.

Reading Locale.getDefault() in a composable trips lint's NonObservableLocale
(the header wouldn't recompose on a locale change). Read the locale from
LocalConfiguration via ConfigurationCompat instead, matching the existing
stats-card pattern, keeping the locale-aware uppercase.
@nbradbury
nbradbury marked this pull request as ready for review July 23, 2026 15:04
@nbradbury
nbradbury requested a review from adalpari July 23, 2026 15:04
@adalpari

Copy link
Copy Markdown
Contributor

It looks like the new logic could end up in a possible crash. So, I would take a look:

CommentsRsTabListScreen.kt:151 — New LazyColumn key-uniqueness constraint can hard-crash where the legacy list only showed a duplicate header (PLAUSIBLE).

Header rows are keyed "header_${row.label}". LazyColumn throws IllegalArgumentException (“Key was already used”) if two rows resolve to the same key. The code relies on the invariant “comments are date-sorted, so a label maps to exactly one contiguous group.” That holds for normal server responses (date-descending pages), so this won’t fire in the common case — but it’s a new constraint: the legacy RecyclerView adapter tolerated duplicate SubHeader(label) values harmlessly. If the server ever returns comments out of strict date order (or a moderation/merge reorders such that two non-adjacent comments share an identical relative/absolute label), the label repeats non-contiguously → duplicate key → crash, where the old list just rendered a redundant header.

Failure scenario: an accumulated rawComments set (multi-page, distinctBy on append) whose order is not strictly monotonic by javaDateToTimeSpan label produces two DateHeader("…") with the same label → IllegalArgumentException on composition. Low probability but a hard crash. Worth a defensive measure (e.g. dedupe/uniquify header keys, or fall back gracefully) given the failure mode is a crash rather than a cosmetic glitch.

The header LazyColumn key relied on the invariant that date-sorted comments make
each label one contiguous group. If the list ever arrived out of date order a
label could repeat non-contiguously, producing a duplicate key -> LazyColumn
IllegalArgumentException (a crash, where the legacy list only showed a redundant
header). withDateHeaders now mints a guaranteed-unique key per header (still just
the label in the normal case, disambiguated only on a non-contiguous repeat), so
correctness no longer depends on the sort order.
@nbradbury

Copy link
Copy Markdown
Contributor Author

It looks like the new logic could end up in a possible crash. So, I would take a look:

Once again I'm surprised that my Claude review didn't uncover this potential problem. Fixed in eeaf9d7.

@adalpari adalpari left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@adalpari

Copy link
Copy Markdown
Contributor

It looks like the new logic could end up in a possible crash. So, I would take a look:

Once again I'm surprised that my Claude review didn't uncover this potential problem. Fixed in eeaf9d7.

I'm in a mode where I always expect new potential issues when someone else reviews my PRs, using the exact ask to Claude I did like 2 or 3 times before opening it. 😅

@nbradbury
nbradbury merged commit 33fe249 into trunk Jul 24, 2026
23 checks passed
@nbradbury
nbradbury deleted the issue/rs-comments-subheaders branch July 24, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants